package com.study.web.action;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.study.web.context.SpringMVCActionSupport;

/**
 * 
 * All rights Reserved, Designed By yaojinshan
 * @Title:  RequestPageController.java   
 * @Package com.study.web.action   
 * @Description:    请求页面控制器   
 * @author: yaojinshan     
 * @date:   2018年6月27日 下午3:36:59   
 * @version V1.0 
 * @Copyright: 2018 All users All rights reserved. 
 * 注意：注意：本内容仅限于学习springmvc + spring + maven + mybatis学习使用
 */
@Controller
@RequestMapping("/admin/page")
public class RequestPageController extends SpringMVCActionSupport {
	/**
	 * 
	 * @param folder1 目录层级1
	 * @return
	 */
	@RequestMapping("/{folder1}")
	public String forward1(@PathVariable String folder1){
		Subject subject =SecurityUtils.getSubject();
		if(!subject.isPermitted(folder1 + ":view")){
			//throw new UnauthenticatedException("");
			return "error/unauth";
		}
		if(!StringUtils.isEmpty(folder1)){
			return folder1.trim();
		}
		return "";
	}
	/**
	 * 
	 * @param folder1  目录层级1
	 * @param folder2  目录层级2
	 * @return
	 */
	@RequestMapping("/{folder1}/{folder2}")
	public String forward2(@PathVariable String folder1,@PathVariable String folder2){
		Subject subject =SecurityUtils.getSubject();
		if(!subject.isPermitted(folder2 + ":view")){
			//throw new UnauthenticatedException("");
			return "error/unauth";
		}
		if(!StringUtils.isEmpty(folder2)){
			return folder1.trim() + "/" + folder2.trim();
		}
		return "";
	}
	/**
	 * 
	 * @param folder1  目录层级1
	 * @param folder2  目录层级2
	 * @param folder3  目录层级3
	 * @return
	 */
	@RequestMapping("/{folder1}/{folder2}/{folder3}")
	public String forward3(@PathVariable String folder1,@PathVariable String folder2,@PathVariable String folder3){
		Subject subject =SecurityUtils.getSubject();
		if(!subject.isPermitted(folder3 + ":view")){
			//throw new UnauthenticatedException("");
			return "error/unauth";
		}
		if(!StringUtils.isEmpty(folder3)){
			return folder1.trim() + "/" + folder2.trim() + "/" + folder3.trim();
		}
		return "";
	}
	/**
	 * 
	 * @param folder1  目录层级1
	 * @param folder2  目录层级2
	 * @param folder3  目录层级3
	 * @param folder4  目录层级4
	 * @return
	 */
	@RequestMapping("/{folder1}/{folder2}/{folder3}/{folder4}")
	public String forward4(@PathVariable String folder1,@PathVariable String folder2,@PathVariable String folder3,@PathVariable String folder4){
		Subject subject =SecurityUtils.getSubject();
		if(!subject.isPermitted(folder4 + ":view")){
			//throw new UnauthenticatedException("");
			return "error/unauth";
		}
		if(!StringUtils.isEmpty(folder4)){
			return folder1.trim() + "/" + folder2.trim() + "/" + folder3.trim() + "/" + folder4.trim();
		}
		return "";
	}
}
